
// var XHR_ = require('./createXHR')
function createXHR(){
    if(typeof XMLHttpRequest != "undefined"){
        return new XMLHttpRequest();
    }else if(typeof ActiveXObject != "undefined"){
        if(typeof arguments.callee.activeXString != "string"){
            var version = ["MSXML2.XMLHttp.6.0","MSXML2.XMLHttp.3.0","MSXMl2.XMLHttp"];
            var i;
            var len;

            for(i =0,len =version.length;i<len;i++){
                try{
                    new ActiveXObject(version[i]);
                    arguments.callee.activeXString = version[i];
                    break;
                }catch(ex){
                    
                }
            }
        }
        return new ActiveXObject(arguments.callee.activeXString);

    }else{
        throw new Error("没有xhr对象")
    }
}

var xhr =new createXHR();

xhr.onreadystatechange =function(){
    if(xhr.readyState == 4){
        if((xhr.status >= 200 && xhr.status <300)||xhr.status == 304){
            alert(xhr.responseText)
        }else{
            alert('请求不成功'+xhr.status)
        }
    }
}

// 进度百分比指示器
// xhr.onprogress = function(event){
//     var divStatus = document.getElementById('status');
//     if(event.lengthComputable){
//         divStatus.innerHTML = "接受"+event.position + "of" +event.totalSize + "b";
//     }
// }

xhr.open('get','test.json',false)
xhr.send(null)
